import io.lettuce.core.RedisClient;
import io.lettuce.core.ScoredValue;
import io.lettuce.core.api.StatefulRedisConnection;

import java.util.List;

public class RedisTestList {
    RedisClient redisClient;
    StatefulRedisConnection<String, String> connection;

    public void link(){
        redisClient = RedisClient.create("redis://localhost");
        connection = redisClient.connect();
        System.out.println("连接");

    }


    public void addSortedSet(){
        connection.sync().zadd("sortedSet",1,"test1");
        connection.sync().zadd("sortedSet",2,"test2");
        connection.sync().zadd("sortedSet",3,"test3");
        connection.sync().zadd("sortedSet",4,"test3");
        List<ScoredValue<String>> sortedSet = connection.sync().zrangeWithScores("sortedSet", 0, -1);
        for(ScoredValue sv:sortedSet){
            System.out.println(sv);
        }
    }


    public void delSortedSet(){
        List<ScoredValue<String>> sortedSet = connection.sync().zrangeWithScores("sortedSet", 0, -1);
        for(ScoredValue sv:sortedSet){
            System.out.println(sv);
        }
        System.out.println();
        connection.sync().zrem("sortedSet","test1");
        sortedSet = connection.sync().zrangeWithScores("sortedSet", 0, -1);
        for(ScoredValue sv:sortedSet){
            System.out.println(sv);
        }
    }


    public void getSortedSet(){
        List<ScoredValue<String>> sortedSet = connection.sync().zrangeWithScores("sortedSet", 0, -1);
        for(ScoredValue sv:sortedSet){
            System.out.println(sv);
        }
    }


    public void finish(){
        connection.close();
        redisClient.shutdown();
        System.out.println("结束");
    }
}


